<?php
define('DEBUG',1);//方便改    传递给程序内app->isDebug


#define('APCU_PREFIX','z3_');//本站缓冲前缀,注意其它站的共用与覆盖,   不定义不影响session与cache 但composer,lang,config 无apcu缓冲

require __DIR__ . '/../vendor/autoload.php';

(new \pidan\App())->setMode('swoole')->setInitializers(['app\mode\swoole\initializer\RegisterService'])->initialize();//只引入app容器，及公共的配置  公共函数

define('APCU_PV',APCU_PREFIX.'pv');//统计pv
apcu_store(APCU_PV, 0);

// 应用初始化
$http = new Swoole\Http\Server('0.0.0.0', 9503);
$http->on('Request', function ($request, $response) use($http) {
    if ($request->server['path_info'] == '/favicon.ico') {
        $response->end();
        return;
    }

    //根据pathinfo得出app controller action
    $path_info=$request->server['path_info'];
    if($path_info=='/'){
        $path_info='/index/index/index';
    }
    list($app,$controller, $action) =explode('/',trim($path_info,'/'));

    $class='\\app\\'.$app.'\\controller\\'.ucfirst($controller);// \app\index\controller\Index
    $app=app();$contr=$app[$class];

    $contr->$action($request, $response);
    $i=apcu_inc(APCU_PV);
    //echo $i.'['.$http->master_pid.'-'.$http->manager_pid.'-'.$http->worker_id.']'."\n";
    //$app->G('end_'.$i,'','',100);

});
$http->start();